package com.y.core.constant;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class PlatForm {
	protected static Logger LOGGER = LogManager.getLogger(PlatForm.class);
	
	private static Map<String, Object> CORECACHE = new HashMap<String, Object>();
	private static Map<String, Object> ACCESS_TOKENS = new HashMap<String, Object>();
	static {
		CORECACHE.put(Const.ACCESS_TOKEN, ACCESS_TOKENS);
	}

	public static void setToken(String username) {
		// 随机数代表Token
		String token = UUID.randomUUID().toString().replaceAll("-", "");
		// 根据用户获取Token
		ACCESS_TOKENS.put(username, token);
		CORECACHE.put(Const.ACCESS_TOKEN, ACCESS_TOKENS);
		LOGGER.info("Token:"+ACCESS_TOKENS);
	}

	public static String getToken(String username) {
		// 根据用户获取Token
		return ACCESS_TOKENS.get(username).toString();
	}

	/**
	 * 获得所有Tokens
	 * 
	 * @return
	 */
	public static Map<String, Object> getACCESS_TOKENS() {
		return ACCESS_TOKENS;
	}

	/**
	 * 获取所有缓存文件
	 * 
	 * @return
	 */
	public static Map<String, Object> getCORECACHE() {
		return CORECACHE;
	}
}
